//
//  MYTableViewController.m
//  13-OutLayout强化
//
//  Created by 李昊林 on 16/8/1.
//  Copyright © 2016年 李昊林. All rights reserved.
//

#import "MYTableViewController.h"
#import "MyTableViewCell.h"
#import "UIView+Frame.h"
#import "SelfSizeTool.h"
#define KTableViewCellReuse @"reuse"
@interface MYTableViewController ()
@property (nonatomic,strong)NSArray *array;
@end

@implementation MYTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.array = @[@"表格必须重用原型标识符",@" Uncomment the following line to preserve selection between presentations.",@" Uncomment the following line to preserve selection between presentations.clearsSelectionOnViewWillAppear = NO"];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    //预估高度
    self.tableView.estimatedRowHeight = 40;
    //高度，自动机选
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    //2.根据label内容去计算并赋予tableView
    //好处：可以存储高度，可以省掉计算的时间
    
    //优先级
    //1.优先级分四档 1000，750，250，50
    //2.高级优先级会先被执行，根据情况，低优先级可能被舍弃
    //3.优先级一般被用来解决约束冲突的问题（解决约束冲突，找关键数字）
    //4.1000的优先级，在xib|sb中为实线，低于1000的优先级为虚线
    //5.还可以运用优先级来做动画效果
    //
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat height = [SelfSizeTool selfSizeWithString:_array[indexPath.row] width:[UIScreen mainScreen].bounds.size.width  font:nil];
    return height + 0.5f;
}

#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _array.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:KTableViewCellReuse forIndexPath:indexPath];
    cell.CustomLable.text = _array[indexPath.row];
    // Configure the cell...
    
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
